package com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.controller;

import com.yonyou.ucf.mdf.app.isvdxq.ReturnResult.DataResult;
import com.yonyou.ucf.mdf.app.isvdxq.common.DxqConfig;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.entity.DeviceLogAddDto;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.entity.DeviceLogEntity;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.service.DeviceLogService;
import com.yonyou.ucf.mdf.app.isvdxq.other.service.BaseService;
import com.yonyou.ucf.mdf.app.isvdxq.utils.RequestTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = {DxqConfig.pre_apiUrl+"/devicelog",DxqConfig.pre_pcUrl+"/devicelog"})
public class DeviceLogController {

    @Autowired
    BaseService baseService;
    @Autowired
    private DeviceLogService deviceLogService;

    /**
     * 根据条件查询分页的设备列表
     *
     * @return 返回列表
     */
    @RequestMapping("/GetDeviceLog")
    public DataResult GetDeviceLog(HttpServletRequest request, String name, String type, String opername,
                                   String devicecode, String devicename,
                                   String status, @RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceLogService.getDeviceLog(tenantId, name, type, opername, devicecode, devicename, status, page,
                pagesize);
    }

    /**
     * 根据ID 查询单条记录
     *
     * @param request 请求信息
     * @param id      设备id
     * @return 返回设备信息
     */
    @RequestMapping("/GetDeviceLogById")
    public DataResult GetDeviceLogById(HttpServletRequest request, String id) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceLogService.getDeviceLogById(tenantId, id);
    }


    /**
     * 添加设备记录信息
     *
     * @param request 请求信息
     * @return 返回格式化请求信息
     */
    @RequestMapping("/AddDeviceLog")
    public DataResult AddDeviceLog(HttpServletRequest request, @RequestBody List<DeviceLogAddDto> deviceLogAddDtos) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceLogService.AddDeviceLog(tenantId, deviceLogAddDtos);
    }

    /**
     * 删除设备记录
     *
     * @param request 请求内容
     * @param id      设备记录Id
     * @return 格式化信息返回
     */

    @RequestMapping("/DeleteDeviceLog")
    public DataResult DelectDevice(HttpServletRequest request, String id) {
        return deviceLogService.DeleteDeviceLog(id);
    }

    @RequestMapping("/DeleteDeviceLogByName")
    public DataResult DeleteDeviceLogByName(HttpServletRequest request, String name) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceLogService.DeleteDeviceLogByName(name, tenantId);
    }

    /**
     * 修改设备记录
     *
     * @param request         请求内容
     * @param id              设备记录id
     * @param deviceLogEntity 设备记录
     * @return
     */
    @RequestMapping("/ModifyDeviceLog")
    public DataResult ModifyDevice(HttpServletRequest request, String id,
                                   @RequestBody DeviceLogEntity deviceLogEntity) {
        return deviceLogService.ModifyDeviceLog(id, deviceLogEntity);
    }


}
